package org.example.system.service.impl;

import org.example.system.common.enums.PayTypeEnum;
import org.example.system.service.PaymentStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class PaymentStrategyContext {

    private static final Map<PayTypeEnum, PaymentStrategy> strategyMap =
            new ConcurrentHashMap<>();

    @Autowired
    public PaymentStrategyContext(List<PaymentStrategy> list){
        list.forEach(strategy -> strategyMap.put(strategy.getPayChannel(), strategy));
    }


    public PaymentStrategy getPaymentStrategy(PayTypeEnum payTypeEnum){
        return strategyMap.get(payTypeEnum);
    }

}
